﻿Imports Microsoft.WindowsAPICodePack.Taskbar
Public Class frmClipboard
    Dim labeltext As String = "Type of data:"

    'Declaration for taskbar buttons
    Private WithEvents SavetoFile, TypeinClip As ThumbnailToolbarButton

    Private Sub cmdGetData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetData.Click
        RichTextBox1.Paste()
        lblType.Text = labeltext & WhatType()    ' Data
    End Sub

    Private Sub frmClipboard_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Save, typeinclp As System.Drawing.Icon
        Save = My.Resources.Resource1.save
        typeinclp = My.Resources.Resource1.shell32_243


        SavetoFile = New ThumbnailToolbarButton(Save, "Save to Clipboard")
        TypeinClip = New ThumbnailToolbarButton(typeinclp, "Type of content in clipboard")
        Dim array1() As Microsoft.WindowsAPICodePack.Taskbar.ThumbnailToolbarButton = {SavetoFile, TypeinClip}
        TaskbarManager.Instance.ThumbnailToolbars.AddButtons(Handle, array1)

    End Sub

    Public Function WhatType() As String
        Dim type As String = String.Empty
        If Clipboard.ContainsImage = True Then
            type = "Image"    ' Image
        ElseIf Clipboard.ContainsAudio = True Then
            type = "Audio"    ' Audio
        ElseIf Clipboard.ContainsText = True Then
            type = "Text"     ' Text
        ElseIf Clipboard.ContainsFileDropList = True Then
            type = "FileDropList"    ' Data
        End If
        Return type
    End Function

    Public Sub TypeinClip_Click() Handles TypeinClip.Click
        MsgBox(WhatType)
    End Sub

    Public Function SaveClip() As Boolean
        Try
            If WhatType() = "Text" Then
                Dim filepath As String = InputBox("Enter the file path to save", "Path", "C:\Clip.txt")
                FileIO.FileSystem.WriteAllText(filepath, Clipboard.GetText & ControlChars.NewLine, True)
            Else
                Throw New Exception("The Clipboard does not contain text")
            End If
        Catch ex As Exception
            Select Case (Err.Number)
                Case 5
                    MessageBox.Show(ex.Message & ControlChars.NewLine & "Error No: " & Err.Number _
                                   & ControlChars.NewLine & "May be you are 'not' running this program as Admin", _
                                   "Error")

                Case Else
                    MessageBox.Show(ex.Message & ControlChars.NewLine _
                                    & "Error No: " & Err.Number & ControlChars.NewLine _
                                    & "Contact intermedia.vishnu@gmail.com for help", "Error")
            End Select

        End Try
    End Function
End Class